//初始化数据参数对象
var initShrObj = {
	CASH_AMT : "0.00",
	WITH_AMT : "0.00",
	SHR_CNT : "0.00",
	SHR_LEVEL_1 : "0.00",
	SHR_LEVEL_2 : "0.00",
	SHR_LEVEL_3 : "0.00",
	USER_CNT : 0,
	USER_CNT_1 : 0,
	USER_CNT_2 : 0,
	USER_CNT_3 : 0,
	CUST_CNT : 0,
	CUST_CNT_0 : 0,
	CUST_CNT_1 : 0
};
function loadShrList(){
	var data = {};
	initShr();
	var data = {
		STARTDATE:$("#beginTime").val(),
		ENDDATE:$("#endTime").val()
		
	};
	formSubmitForAjax({
		url: BASE_PATH + "getShrInfo.web",
		data:data,
		success : function(json){
			if(codeSuccess(json)){
				var shrList = json['SHR_LIST'];
				var len = 0;
				if(shrList && (len=shrList.length) > 0){
					//汇总对象
					var cntObj = {
							SHR_TYPE : 0,
							SHR_CNT : 0,
							CASH_AMT : 0,
							WITH_AMT : 0,
							SHR_LEVEL_1 : 0,
							SHR_LEVEL_2 : 0
					};
					var obj;
					var SHR_TYPE = -1;
					for (var i = 0; i < len; i++) {
						obj = shrList[i];
						SHR_TYPE = obj["SHR_TYPE"];
						//提现
						if(SHR_TYPE == -1){
							continue;
						}
						cntObj["SHR_CNT"] = (cntObj["SHR_CNT"] - 0) + (obj["SHR_CNT"] - 0);//总利润
						cntObj["SHR_LEVEL_1"] = (cntObj["SHR_LEVEL_1"] - 0) + (obj["SHR_LEVEL_1"] - 0);//直接收入
						cntObj["SHR_LEVEL_2"] = (cntObj["SHR_LEVEL_2"] - 0) + ((obj["SHR_LEVEL_2"] || 0) - 0);//团队收入
						cntObj["SHR_LEVEL_2"] = (cntObj["SHR_LEVEL_2"] - 0) + ((obj["SHR_LEVEL_3"] || 0) - 0);//团队收入
						cntObj["CASH_AMT"] = obj["CASH_AMT"];//未提
						
//						alert(".SHR_TYPE_" + obj['SHR_TYPE']);
						fillShr(obj);
					}
					cntObj["WITH_AMT"] = cntObj["SHR_CNT"] - obj["CASH_AMT"];//已结算金额
					cntObj["WITH_AMT"] = cntObj["SHR_CNT"] - obj["CASH_AMT"];//已结算金额
					fillShr(cntObj);
				}
				
				var AGENT_CUST_CNT = json["AGENT_CUST_CNT"];
				if(AGENT_CUST_CNT){
					var $table = $("[id^='AGENT_CUST_CNT'],[ref^='AGENT_CUST_CNT']");
					if ($table && $table.length > 0) {
						// 填充表格
						fillTable($table, AGENT_CUST_CNT);
					}
				}
			}
		}
	});
}

function initShr(){
	var $table = $("[id^='SHR_TYPE_'],[ref^='SHR_TYPE_'],[id='AGENT_CUST_CNT'],[ref='AGENT_CUST_CNT']");
	if ($table && $table.length > 0) {
		// 填充表格
		fillTable($table, initShrObj);
	}
}

function fillShr(obj){
	var id = "SHR_TYPE_" + obj['SHR_TYPE'];
	var $table = $("#" + id+",[ref='"+id+"']");
	if ($table && $table.length > 0) {
		// 填充表格
		fillTable($table, obj);
	}
}

function setAmt(data){
	
}
function initAmt(){
	$(".shr-amt").html('0');
}

//加载完成执行
$(document).ready(function() {
	$('#SHR_TYPE_0,#SHR_TYPE_1,#SHR_TYPE_2,#AGENT_CUST_CNT').on('click',function(){
		var $this = $(this);
		var id = $this.attr('id');
		var $subMenu = $('.sub-menu-box[ref="'+id+'"]');
		//alert($subMenu.attr('class'));
		//如果当前时隐藏，则点击就展开
		if($subMenu.is(":hidden")){
			$('img[class="arrow"]',$this).attr('src','images/arrow-expand.png');
			$subMenu.show();
		}else{
			$('img[class="arrow"]',$this).attr('src','images/arrow.png');
			$subMenu.hide();
		}
		
	});
});

